/*
 * Copyright 2014 JootMir Project
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Support: http://www.jootmir.org
 */
package org.jootmir.client;

import java.awt.Canvas;
import java.util.Arrays;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

import org.jootmir.client.core.Application;
import org.jootmir.client.core.ApplicationConfig;
import org.jootmir.client.core.util.Kit;
import org.jootmir.client.game.MapTest;

public class Launcher {

	public static void main(String[] args) {
		ApplicationConfig config = new ApplicationConfig();
		// 在此处进行配置
		config.width = 1280;
		config.height = 720;
		//config.fullscreen = true;

		// 以下代码请勿修改
		try {
			//UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
			UIManager.setLookAndFeel(new NimbusLookAndFeel());
		} catch (Exception ex) {
			// 不做任何事
		}
		if(!config.fullscreen) {
			/* 使用Java-AWT窗体来承载游戏绘制区域，使不同种类事件两相分离；绘制游戏区域时不会卡顿 */
			JFrame f = new JFrame();
			f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
			f.setTitle(config.title);
			f.setResizable(false);
			f.setIconImages(Arrays.asList(Kit.image(config.icon16Path), Kit.image(config.icon32Path), Kit.image(config.icon128Path)));
			Canvas c = new Canvas();
			c.setSize(config.width, config.height);
			f.add(c);
			f.setVisible(true);
			f.setSize(f.getInsets().left + config.width + f.getInsets().right,
					f.getInsets().top + config.height + f.getInsets().bottom);
			f.setLocationRelativeTo(null);
			config.parent = c;
			config.window = f;
		}
		
		Application.get().initialize(config, new MapTest());
		//Application.get().initialize(config, new FontTest());
		Application.get().mainLoop();
	}

}